//
//  ServiceNews.m
//  suRead
//
//  Created by lidi on 15/11/6.
//  Copyright © 2015年 bao. All rights reserved.
//

#import "ServiceNews.h"
#import "M_News.h"
#import "M_NewsDetail.h"
#import "M_Report.h"
#import "AccountManager.h"
#import "M_Comment.h"
#import "SDWebImageDownloader.h"
#import "SDImageCache.h"
#import "M_tags.h"
#import "M_Letter.h"
#import "M_MyComment.h"
#import "M_SpecialNews.h"
#import "M_WenbaDetail.h"
#import "M_QuestionComment.h"
#import "M_PlayNewsDetail.h"
#import "M_AppOpenImage.h"

#import "ServiceUserNew.h"

@implementation ServiceNews

/**
 *  新闻搜索
 *
 *  @param keyword_ 搜索关键字
 *  @param success_
 *  @param failure_
 *
 *  @return
 */
+ (NSURLSessionDataTask *)doSearchNewsList:(NSString *)keyword_
                                pageindex:(NSInteger)pageindex_
                                 pagesize:(NSInteger)pagesize_
                                  success:(void (^)(id responseObject,NSString *message))success_
                                  failure:(void (^)(NSString *message))failure_
{
    NSString *urlString = url_net_search_news;
    urlString = [urlString stringByAppendingFormat:@"&keyword=%@&pageindex=%ld&pagesize=%ld",keyword_,pageindex_,pagesize_];
    urlString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    return [[ServiceUtils commonHTTPManager] GET:urlString parameters:nil progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask *task, id responseObject) {
        
        if (responseObject && [responseObject isKindOfClass:[NSDictionary class]]) {
            NSInteger code = [[responseObject objectForKey:@"success"] integerValue];
            NSString *message = [responseObject objectForKey:@"msg"];
            NSArray *data = [responseObject objectForKey:@"data"];
            
            if (code == 1) {
                
                NSError *error;
                NSArray *list = [MTLJSONAdapter modelsOfClass:[M_News class] fromJSONArray:data error:&error];
                if (!list) {
                    list = @[];
                }

                
                success_(list,message);
            } else {
                failure_(message);
            }
        }
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        if (failure_) {
            failure_(@"网络不给力");
        }
    }];
}


/**
 *  搜索关键字列表
 *
 *  @param success_
 *  @param failure_
 *
 *  @return
 */
+ (NSURLSessionDataTask *)doFetchKeywords:(void (^)(id responseObject,NSString *message))success_
                                  failure:(void (^)(NSString *message))failure_
{
    return [[ServiceUtils commonHTTPManager] POST:url_net_search_keywords parameters:nil progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask *task, id responseObject) {
        
        if (responseObject && [responseObject isKindOfClass:[NSDictionary class]]) {
            NSInteger code = [[responseObject objectForKey:@"success"] integerValue];
            NSString *message = [responseObject objectForKey:@"msg"];
            id data = [responseObject objectForKey:@"data"];
            
            if (code == 200) {
                success_(data,message);
            }
        }
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        if (failure_) {
            failure_(@"网络不给力");
        }
    }];
}


/**
 *  阅读数发送
 *
 *  @param id_
 *  @param success_
 *  @param failure_
 *
 *  @return
 */
+ (NSURLSessionDataTask *)doSendRead:(NSString *)id_
                             success:(void (^)(id responseObject,NSString *message))success_
                             failure:(void (^)(NSString *message))failure_
{
    NSString *urlString = [URL_SUB_READ stringByAppendingFormat:@"&id=%@",id_];
    
    return [[ServiceUtils commonHTTPManager] POST:urlString parameters:nil progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask *task, id responseObject) {
        if (success_) {
            success_(nil,@"发送成功");
        }
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        if (failure_) {
            failure_(@"网络不给力");//返回的不是json不用管
        }
    }];
}


/**
 *  获取tags
 *
 *  @param success_
 *  @param failure_
 *
 *  @return
 */
+ (NSURLSessionDataTask *)doFetchTags:(void (^)(id responseObject,NSString *message))success_
                              failure:(void (^)(NSString *message))failure_
{
    return [[ServiceUtils commonHTTPManager] GET:URL_SUB_GET_TAGS parameters:nil progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask *task, id responseObject) {
        
        if (responseObject && [responseObject isKindOfClass:[NSArray class]]) {
            NSError *erro;
            NSArray *tags = [MTLJSONAdapter modelsOfClass:[M_tags class] fromJSONArray:responseObject error:&erro];
            if (!tags) {
                tags = @[];
            }
            success_(tags,@"获取成功");
        }
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        if (failure_) {
            failure_(@"网络不给力");
        }
    }];
}

/**
 *  获取新闻列表
 *
 *  @param type_    1 刷新  2 加载更多
 *  @param subURL_  子链接
 *  @param success_
 *  @param failure_
 *
 *  @return
 */
+ (NSURLSessionDataTask *)doFetchNewsList:(RequestType)type_
                                   subURL:(NSString *)subURL_
                                pageIndex:(NSInteger)pageIndex_
                                 pageSize:(NSInteger)pageSize_
                                  success:(void (^)(id responseObject,NSString *message))success_
                                  failure:(void (^)(NSString *message))failure_
{
    NSString *urlString = [URL_BASE stringByAppendingString:subURL_];
    if([subURL_ containsString:@"http://"]){
        urlString=subURL_;
    }
    
    urlString = [urlString stringByAppendingFormat:@"&pageindex=%ld&pagesize=%ld",pageIndex_,pageSize_];
        
    return [[ServiceUtils commonHTTPManager] GET:urlString parameters:nil progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask *task, id responseObject) {
        
        NSMutableDictionary *resDic = [NSMutableDictionary dictionary];

        if (responseObject && [responseObject isKindOfClass:[NSArray class]]) {
            for (NSDictionary *itemDic in responseObject) {
                
                NSString *type = [itemDic objectForKey:@"type"];
                if ([type isEqualToString:@"focus"]) {
                    //焦点图
                    NSArray *dataArray = [itemDic objectForKey:@"item"];
                    NSArray *focus = [MTLJSONAdapter modelsOfClass:[M_News class] fromJSONArray:dataArray error:nil];
                    if (!focus) {
                        focus = @[];
                    }
                    
                    [resDic setObject:focus forKey:@"focus"];
                }
                
                if ([type isEqualToString:@"list"]) {
                    NSError *error;
                    NSArray *dataArray = [itemDic objectForKey:@"item"];
                    NSArray *list = [MTLJSONAdapter modelsOfClass:[M_News class] fromJSONArray:dataArray error:&error];
                    if (!list) {
                        list = @[];
                    }
                    [resDic setObject:list forKey:@"list"];
                    
                }
            }
        }else if (responseObject && [responseObject isKindOfClass:[NSDictionary class]]){
            NSError *error;
            NSArray *dataArray = [responseObject objectForKey:@"item"];
            NSArray *list = [MTLJSONAdapter modelsOfClass:[M_News class] fromJSONArray:dataArray error:&error];
            if (!list) {
                list = @[];
            }
            [resDic setObject:list forKey:@"list"];
        }
        success_(resDic,@"获取成功");
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        if (failure_) {
            failure_(@"网络不给力");
        }
    }];
}

/**
 *  获取首页焦点图列表
 *  @param success_
 *  @param failure_
 *
 *  @return
 */
+ (NSURLSessionDataTask *)doFetchHomeFocusList:(void (^)(id responseObject,NSString *message))success_
                                       failure:(void (^)(NSString *message))failure_ {
    NSString *urlString = @"http://www3.ctdsb.net/index.php?m=app&c=kctFIFA&a=position";
    
    return [[ServiceUtils commonHTTPManager] GET:urlString parameters:nil progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask *task, id responseObject) {
        
        NSMutableArray *resArr = [NSMutableArray array];
        
        if (responseObject && [responseObject isKindOfClass:[NSArray class]]) {
            for (NSDictionary *itemDic in responseObject) {
                NSString *type = [itemDic objectForKey:@"type"];
                
                id content = [itemDic objectForKey:@"content"];
                if (type && [type isKindOfClass:[NSString class]] && [type length] > 0 &&
                    content && [content isKindOfClass:[NSArray class]] && [content count] > 0) {
                    NSError *error;
                    NSArray *list = [MTLJSONAdapter modelsOfClass:[M_News class] fromJSONArray:content error:&error];
                    if (!list) {
                        list = @[];
                    }
                    
                    if (list && [list isKindOfClass:[NSArray class]] && [list count] > 0) {
                        [resArr addObject:@{@"type":type,@"content":list}];
                    }
                }
            }
        }
        
        success_(resArr,@"获取成功");
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        if (failure_) {
            failure_(@"网络不给力");
        }
    }];
}

/**
 *  获取"专题"新闻列表
 *
 *  @param subURL_  子链接
 *  @param success_
 *  @param failure_
 *
 *  @return
 */
+ (NSURLSessionDataTask *)doFetchSpecialNewsList:(NSString *)subURL_
                                         success:(void (^)(id responseObject,NSString *message))success_
                                         failure:(void (^)(NSString *message))failure_
{
    return [[ServiceUtils commonHTTPManager] GET:subURL_ parameters:nil progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask *task, id responseObject) {
        
        NSInteger code = [[responseObject objectForKey:@"success"] integerValue];
        NSString *message = [responseObject objectForKey:@"msg"];
        NSDictionary *data = [responseObject objectForKey:@"data"];
        
        if (code == 1)
        {
            NSMutableDictionary *resDic = [NSMutableDictionary dictionary];
            
            if ([data objectForKey:@"sphead"]) {
                NSArray *dataArray = [data objectForKey:@"sphead"];
                NSArray *focus = [MTLJSONAdapter modelsOfClass:[M_SpecialNews class] fromJSONArray:dataArray error:nil];
                if (!focus) {
                    focus = @[];
                }
                
                [resDic setObject:focus forKey:@"focus"];

            }
            
            if ([data objectForKey:@"listdata"]) {
                
                NSMutableArray *list = [NSMutableArray array];
                
                for (NSDictionary *d in [data objectForKey:@"listdata"]) {
                    NSMutableDictionary *item = [NSMutableDictionary dictionary];
                    [item setObject:[d objectForKey:@"name"] forKey:@"name"];
                    NSError *error;
                    NSArray *dataArray = [d objectForKey:@"item"];
                    NSArray *itemData = [MTLJSONAdapter modelsOfClass:[M_SpecialNews class] fromJSONArray:dataArray error:&error];
                    if (!itemData) {
                        itemData = @[];
                    }
                    [item setObject:itemData forKey:@"item"];
                    
                    [list addObject:item];
                }
                
                [resDic setObject:list forKey:@"list"];
            }
            success_(resDic,@"获取成功");
        }
        else
        {
            failure_(message);
        }
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        if (failure_) {
            failure_(@"网络不给力");
        }
    }];
}

/**
 *  获取"问吧专题"新闻列表
 *
 *  @param subURL_  子链接
 *  @param success_
 *  @param failure_
 *
 *  @return
 */
+ (NSURLSessionDataTask *)doFetchWenBaCtgNewsList:(NSString *)subURL_
                                         pageIndex:(NSInteger)pageIndex_
                                         pageSize:(NSInteger)pageSize_
                                         success:(void (^)(id responseObject,NSString *message))success_
                                         failure:(void (^)(NSString *message))failure_
{
    NSString *urlString = [subURL_ stringByAppendingFormat:@"&pageindex=%ld&pagesize=%ld",pageIndex_,pageSize_];
    return [[ServiceUtils commonHTTPManager] GET:urlString parameters:nil progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask *task, id responseObject) {
        
        NSInteger code = [[responseObject objectForKey:@"success"] integerValue];
        NSString *message = [responseObject objectForKey:@"msg"];
        NSDictionary *data = [responseObject objectForKey:@"data"];
        
        if (code == 200)
        {
            NSMutableDictionary *resDic = [NSMutableDictionary dictionary];
            if([data objectForKey:@"biaoqian_name"]){
                NSString *title=[data objectForKey:@"biaoqian_name"];
                [resDic setObject:title forKey:@"title"];
            }
            
            if ([data objectForKey:@"item"]) {
                NSError *error;
                NSArray *dataArray = [data objectForKey:@"item"];
                NSArray *list = [MTLJSONAdapter modelsOfClass:[M_News class] fromJSONArray:dataArray error:&error];
                if (!list) {
                    list = @[];
                }
                [resDic setObject:list forKey:@"list"];
            }
            success_(resDic,@"获取成功");
        }
        else
        {
            failure_(message);
        }
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        if (failure_) {
            failure_(@"网络不给力");
        }
    }];
}

/**
 *  获取新闻详情
 *
 *  @param urlString_ 请求链接
 *  @param success_
 *  @param failure_
 *
 *  @return
 */
+ (NSURLSessionDataTask *)doFetchNewsDetail:(NSString *)urlString_
                                    success:(void (^)(id responseObject,NSString *message))success_
                                    failure:(void (^)(NSString *message))failure_
{
    return [[ServiceUtils commonHTTPManager] GET:urlString_ parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        
        if (responseObject && [responseObject isKindOfClass:[NSDictionary class]]) {
            
            M_NewsDetail *detail = [MTLJSONAdapter modelOfClass:[M_NewsDetail class] fromJSONDictionary:responseObject error:nil];
            success_(detail,@"获取成功");
            
            // 流量新闻详情，记录足迹
            [ServiceUserNew doLogNews:detail.f_docid success:^(id  _Nonnull responseObject, NSString * _Nonnull message) {
            } failure:^(NSString * _Nonnull message) {
            }];
        }
        else {
            if (failure_) {
                failure_(@"网络不给力");
            }
        }
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        if (failure_) {
            failure_(@"网络不给力");
        }
    }];
}

/**
 *  获取问吧详情
 *
 *  @param urlString_ 请求链接
 *  @param success_
 *  @param failure_
 *
 *  @return
 */
+ (NSURLSessionDataTask *)doFetchWenBaDetail:(NSString *)urlString_
                                    success:(void (^)(id responseObject,NSString *message))success_
                                    failure:(void (^)(NSString *message))failure_
{
    return [[ServiceUtils commonHTTPManager] GET:urlString_ parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        
        if (responseObject && [responseObject isKindOfClass:[NSDictionary class]]) {
            NSInteger code = [[responseObject objectForKey:@"success"] integerValue];
            NSString *message = [responseObject objectForKey:@"msg"];
            NSDictionary *data = [responseObject objectForKey:@"data"];
            
            if (code == 200)
            {
                M_WenbaDetail *detail = [MTLJSONAdapter modelOfClass:[M_WenbaDetail class] fromJSONDictionary:data error:nil];
                success_(detail,@"获取成功");
            }
            else
            {
                failure_(message);
            }
            
        
        }
        else {
            if (failure_) {
                failure_(@"网络不给力");
            }
        }
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        if (failure_) {
            failure_(@"网络不给力");
        }
    }];
}

/**
 *  图秀列表
 *
 *  @param success_
 *  @param failure_
 *
 *  @return
 */
+ (NSURLSessionDataTask *)doFetchPhotoShowList:(void (^)(id responseObject,NSString *message))success_
                                       failure:(void (^)(NSString *message))failure_
{
    NSString *urlString = [NSString stringWithFormat:@"%@%@",URL_BASE,URL_SUB_PHOTO_SHOW];
    
    return [[ServiceUtils commonHTTPManager] GET:urlString parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        
        NSArray *resArray = @[];
        
        if (responseObject && [responseObject isKindOfClass:[NSArray class]]) {
            for (NSDictionary *itemDic in responseObject) {
                
                NSString *type = [itemDic objectForKey:@"type"];
                
                if ([type isEqualToString:@"list"]) {
                    //焦点图
                    NSArray *dataArray = [itemDic objectForKey:@"item"];
                    resArray = [MTLJSONAdapter modelsOfClass:[M_News class] fromJSONArray:dataArray error:nil];
                    if (!resArray) {
                        resArray = @[];
                    }
                    
                }
            }
        }
        success_(resArray,@"获取成功");
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        if (failure_) {
            failure_(@"网络不给力");
        }
    }];
}

/**
 *  掌报
 *
 *  @param success_
 *  @param failure_
 *
 *  @return
 */
+ (NSURLSessionDataTask *)doFetchPocketNewsURL:(void (^)(id responseObject,NSString *message))success_
                                       failure:(void (^)(NSString *message))failure_
{
    NSString *urlString = [NSString stringWithFormat:@"%@%@",URL_BASE,URL_SUB_POCKTE_NEWS];
    
    return [[ServiceUtils commonHTTPManager] GET:urlString parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        
        NSString *resString = @"";
        
        if (responseObject && [responseObject isKindOfClass:[NSDictionary class]]) {
            resString = [responseObject objectForKey:@"source_url"];
            if (!resString) {
                resString = @"";
            }
        }
        success_(resString,@"获取成功");
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        if (failure_) {
            failure_(@"网络不给力");
        }
    }];
}

/**
 *  互动列表
 *
 *  @param success_
 *  @param failure_
 *
 *  @return
 */
+ (NSURLSessionDataTask *)doFetchInteractiveList:(NSInteger)pageIndex_
                                        pageSize:(NSInteger)pageSize_
                                         success:(void (^)(id responseObject,NSString *message))success_
                                         failure:(void (^)(NSString *message))failure_
{
    NSString *urlString = [NSString stringWithFormat:@"%@%@",URL_BASE,URL_SUB_INTERACTIVE];
    
    urlString = [urlString stringByAppendingFormat:@"&pageindex=%ld&pagesize=%ld",pageIndex_,pageSize_];

    return [[ServiceUtils commonHTTPManager] GET:urlString parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        
        NSArray *resArray = @[];
        
        if (responseObject && [responseObject isKindOfClass:[NSArray class]]) {
            for (NSDictionary *itemDic in responseObject) {
                
                NSString *type = [itemDic objectForKey:@"type"];
                
                if ([type isEqualToString:@"list"]) {
                    //焦点图
                    NSArray *dataArray = [itemDic objectForKey:@"item"];
                    resArray = [MTLJSONAdapter modelsOfClass:[M_News class] fromJSONArray:dataArray error:nil];
                    if (!resArray) {
                        resArray = @[];
                    }
                    
                }
            }
        }
        success_(resArray,@"获取成功");
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        if (failure_) {
            failure_(@"网络不给力");
        }
    }];
}

/**
 *  报料列表
 *
 *  @param pageIndex_
 *  @param pageSize_
 *  @param success_
 *  @param failure_
 *
 *  @return
 */
+ (NSURLSessionDataTask *)doFetchReportList:(NSInteger)pageIndex_
                                   pageSize:(NSInteger)pageSize_
                                    success:(void (^)(id responseObject,NSString *message))success_
                                    failure:(void (^)(NSString *message))failure_
{
    NSString *urlString = [URL_SUB_REPORT_LIST stringByAppendingFormat:@"&pageindex=%ld&pagesize=%ld",pageIndex_,pageSize_];

    return [[ServiceUtils commonHTTPManager] GET:urlString parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        
        if (responseObject && [responseObject isKindOfClass:[NSDictionary class]]) {
            
            NSInteger code = [[responseObject objectForKey:@"success"] integerValue];
            NSString *message = [responseObject objectForKey:@"msg"];
            NSArray *datas = [[responseObject objectForKey:@"data"] objectForKey:@"items"];
            
            if (code == 1) {
                
                NSArray *reports = [MTLJSONAdapter modelsOfClass:[M_Report class] fromJSONArray:datas error:nil];
                if (!reports) {
                    reports = @[];
                }
                
                success_(reports,@"获取成功");
            }
            else {
                failure_(message);
            }
            
        }
        else {
            failure_(@"网络不给力");
        }
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        if (failure_) {
            failure_(@"网络不给力");
        }
    }];
}

/**
 *  注册
 *
 *  @param username_
 *  @param nickname_
 *  @param email_
 *  @param mobile_
 *  @param password_
 *  @param success_
 *  @param failure_
 *
 *  @return
 */
+ (NSURLSessionDataTask *)doRegister:(NSString *)username_
                            nickname:(NSString *)nickname_
                               email:(NSString *)email_
                              mobile:(NSString *)mobile_
                            password:(NSString *)password_
                             success:(void (^)(id responseObject,NSString *message))success_
                             failure:(void (^)(NSString *message))failure_
{
    NSString *urlString = [URL_BASE stringByAppendingString:@"index.php?m=app&c=member&a=register"];
    
    NSDictionary *dic = @{@"username": username_,@"nickname": nickname_,@"email": email_,@"mobile": mobile_,@"password": password_};
    
    return [[ServiceUtils commonHTTPManager] POST:urlString
                                       parameters:dic
                                          success:^(NSURLSessionDataTask *task, id responseObject)
    {
        
        if (responseObject && [responseObject isKindOfClass:[NSDictionary class]]) {
            
            NSInteger code = [[responseObject objectForKey:@"success"] integerValue];
            NSString *message = [responseObject objectForKey:@"msg"];
            NSDictionary *data = [responseObject objectForKey:@"data"] ;
            
            if (code == 1) {
                AccountManager *acManager = [AccountManager sharedAccountManager];
                acManager.f_isLogined = YES;
                acManager.f_userName = username_;
                acManager.f_uid = [data objectForKey:@"userid"];
                acManager.f_email = email_;
                
                success_(nil,@"注册成功");
            }
            else {
                failure_(message);
            }
        }
        else {
            failure_(@"网络不给力");
        }
        
    }
                                          failure:^(NSURLSessionDataTask *task, NSError *error)
    {
        if (failure_) {
            failure_(@"网络不给力");
        }
    }];
}

/**
 *  登录
 *
 *  @param username_
 *  @param password_
 *  @param success_
 *  @param failure_
 *
 *  @return
 */
+ (NSURLSessionDataTask *)doLogin:(NSString *)username_
                         password:(NSString *)password_
                          success:(void (^)(id responseObject,NSString *message))success_
                          failure:(void (^)(NSString *message))failure_
{
    NSString *urlString = [URL_BASE stringByAppendingString:@"index.php?m=app&c=member&a=verify"];
    
    NSDictionary *dic = @{@"username": username_,@"password": password_};
    
    return [[ServiceUtils commonHTTPManager] POST:urlString
                                       parameters:dic
                                          success:^(NSURLSessionDataTask *task, id responseObject)
    {
        if (responseObject && [responseObject isKindOfClass:[NSDictionary class]]) {
            
            NSInteger code = [[responseObject objectForKey:@"success"] integerValue];
            NSString *message = [responseObject objectForKey:@"msg"];
            NSDictionary *data = [responseObject objectForKey:@"data"] ;
            
            if (code == 1) {
                AccountManager *acManager = [AccountManager sharedAccountManager];
                acManager.f_isLogined = YES;
                acManager.f_userName = [data objectForKey:@"username"];
                acManager.f_uid = [data objectForKey:@"uid"];
                acManager.f_nickname = [data objectForKey:@"nickname"];
                acManager.f_email = [data objectForKey:@"email"];
                
                success_(nil,@"登录成功");
            }
            else {
                failure_(message);
            }
        }
        else {
            failure_(@"网络不给力");
        }
    }
                                          failure:^(NSURLSessionDataTask *task, NSError *error)
            
    {
        if (failure_)
        {
            failure_(@"网络不给力");
        }
    }];
}

/**
 *  第三方登录
 *
 *  @param username_
 *  @param openid_
 *  @param success_
 *  @param failure_
 *
 *  @return
 */
+ (NSURLSessionDataTask *)doLoginByThirdPart:(NSString *)username_
                                      openid:(NSString *)openid_
                                     success:(void (^)(id responseObject,NSString *message))success_
                                     failure:(void (^)(NSString *message))failure_
{
    NSString *urlString = [URL_BASE stringByAppendingString:@"index.php?m=app&c=member&a=registerbyopenid"];
    
    NSDictionary *dic = @{@"username": username_,@"nickname": username_,@"openid": openid_};
    
    return [[ServiceUtils commonHTTPManager] POST:urlString parameters:dic success:^(NSURLSessionDataTask *task, id responseObject) {
        
        if (responseObject && [responseObject isKindOfClass:[NSDictionary class]]) {
            
            NSInteger code = [[responseObject objectForKey:@"success"] integerValue];
            NSString *message = [responseObject objectForKey:@"msg"];
            NSDictionary *data = [responseObject objectForKey:@"data"] ;
            
            if (code == 1) {
                AccountManager *acManager = [AccountManager sharedAccountManager];
                acManager.f_isLogined = YES;
                acManager.f_userName = username_;
                acManager.f_uid = [data objectForKey:@"userid"];
                
                success_(nil,@"登录成功");
            }
            else {
                failure_(message);
            }
        }
        else {
            failure_(@"网络不给力");
        }
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        if (failure_) {
            failure_(@"网络不给力");
        }
    }];
}

/**
 *  图片上传
 *
 *  @param imageFilePath_ 图片本地地址
 *  @param success_
 *  @param failure_
 *
 *  @return
 */
+ (NSURLSessionUploadTask *)doUpdatePhotoList:(NSString *)imageFilePath_
                                      success:(void (^)(id responseObject,NSString *message))success_
                                      failure:(void (^)(NSString *message))failure_
{
    NSString *urlString = [URL_BASE stringByAppendingString:@"index.php?m=app&c=upload&a=imgfile"];

    NSMutableURLRequest *request = [[AFHTTPRequestSerializer serializer]
                                    multipartFormRequestWithMethod:@"POST"
                                    URLString:urlString
                                    parameters:nil
                                    constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
                                        
                                        [formData appendPartWithFileURL:[NSURL fileURLWithPath:imageFilePath_] name:@"imgfile" fileName:@"test.png" mimeType:@"image/png" error:nil];
                                        
                                    } error:nil];
    
    AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
    
    AFJSONResponseSerializer *responseSerializer = [AFJSONResponseSerializer serializer];
    responseSerializer.acceptableContentTypes = [NSSet setWithArray:@[@"text/html",@"application/json"]];
    manager.responseSerializer = responseSerializer;
    
    NSURLSessionUploadTask *task = [manager uploadTaskWithStreamedRequest:request progress:nil completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
        if(!error)
        {
            if ([responseObject isKindOfClass:[NSDictionary class]]) {
                NSDictionary *responseDic = (NSDictionary *)responseObject;
                if ([[responseDic objectForKey:@"success"] integerValue] == 1) {
                    success_([responseDic objectForKey:@"imgurl"],@"上传成功");
                }else {
                    failure_(@"上传失败");
                }
            }
            else
            {
                if (failure_) {
                    failure_(@"上传失败");
                }
            }
        }
        else {
            if (failure_) {
                failure_(@"网络不给力");
            }
        }
        
    }];
    
    [task resume];
    return task;
}


/**
 *  报料发布
 *
 *  @param title_
 *  @param content_
 *  @param imgs_
 *  @param contact_
 *  @param username_
 *  @param success_
 *  @param failure_
 *
 *  @return
 */
+ (NSURLSessionDataTask *)doReport:(NSString *)title_
                           content:(NSString *)content_
                              imgs:(NSString *)imgs_
                           contact:(NSString *)contact_
                          username:(NSString *)username_
                          ispublic:(BOOL)ispublic_
                           success:(void (^)(id responseObject,NSString *message))success_
                           failure:(void (^)(NSString *message))failure_
{
    NSString *urlString = [URL_BASE stringByAppendingString:URL_SUB_REPORT];
    
    NSDictionary *dic = @{@"title": title_,
                          @"catid": @(34),
                          @"content": content_,
                          @"imgs": imgs_ == nil ? @"" : imgs_,
                          @"contact": contact_ == nil ? @"" : contact_,
                          @"uct":[self getAuthCode],
                          @"username": username_,
                          @"ispublic": @(ispublic_)};
    
    return [[ServiceUtils commonHTTPManager] POST:urlString parameters:dic success:^(NSURLSessionDataTask *task, id responseObject) {
        
        success_(nil,@"发布成功");
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        if (failure_) {
            failure_(@"网络不给力");
        }
    }];
}

/**
 *  反馈
 *
 *  @param content_
 *  @param username_
 *  @param success_
 *  @param failure_
 *
 *  @return
 */
+ (NSURLSessionDataTask *)doFeedBack:(NSString *)content_
                            username:(NSString *)username_
                             success:(void (^)(id responseObject,NSString *message))success_
                             failure:(void (^)(NSString *message))failure_
{
    NSString *urlString = [URL_BASE stringByAppendingString:URL_SUB_REPORT];
    
    NSDictionary *dic = @{@"content": content_,
                          @"catid": @(26),
                          @"uct":[self getAuthCode],
                          @"username": username_};
    
    return [[ServiceUtils commonHTTPManager] POST:urlString parameters:dic success:^(NSURLSessionDataTask *task, id responseObject) {
        
        success_(nil,@"发布成功");
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        if (failure_) {
            failure_(@"网络不给力");
        }
    }];
}

/**
 *  报料内容
 *
 *  @param baoliaoid_
 *  @param success_
 *  @param failure_
 *
 *  @return
 */
+ (NSURLSessionDataTask *)doReportDetail:(NSString *)baoliaoid_
                                 success:(void (^)(id responseObject,NSString *message))success_
                                 failure:(void (^)(NSString *message))failure_
{
    NSString *urlString = [URL_SUB_REPORT_DETAIL stringByAppendingFormat:@"&baoliaoid=%@",baoliaoid_];
    
    return [[ServiceUtils commonHTTPManager] GET:urlString parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        
        if (responseObject && [responseObject isKindOfClass:[NSDictionary class]]) {
            
            NSInteger code = [[responseObject objectForKey:@"success"] integerValue];
            NSString *message = [responseObject objectForKey:@"msg"];
            NSDictionary *data = [responseObject objectForKey:@"data"];
            
            if (code == 1) {
                M_Report *report =  [MTLJSONAdapter modelOfClass:[M_Report class] fromJSONDictionary:data error:nil];
                success_(report,@"获取成功");
            }
            else {
                failure_(message);
            }
            
        }
        else {
            failure_(@"网络不给力");
        }    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        if (failure_) {
            failure_(@"网络不给力");
        }
    }];

}

/**
 *  获取新闻评论
 *
 *  @param urlString_ 请求链接
 *  @param success_
 *  @param failure_
 *
 *  @return
 */
+ (NSURLSessionDataTask *)doFetchNewsComment:(NSString *)urlString_
                                     success:(void (^)(id responseObject,NSString *message))success_
                                     failure:(void (^)(NSString *message))failure_
{
    return [[ServiceUtils commonHTTPManager] GET:urlString_ parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        
        NSInteger code = [[responseObject objectForKey:@"success"] integerValue];
        NSString *message = [responseObject objectForKey:@"msg"];
        NSArray *datas = [responseObject objectForKey:@"data"];
        
        if (code == 1) {
            
            NSArray *reports = [MTLJSONAdapter modelsOfClass:[M_Comment class] fromJSONArray:datas error:nil];
            if (!reports) {
                reports = @[];
            }
            success_(reports,@"获取成功");
        }
        else {
            if (failure_) {
                failure_(message);
            }
        }
    }
    failure:^(NSURLSessionDataTask *task, NSError *error) {
            if (failure_) {
            failure_(@"网络不给力");
        }
    }];
}

/**
 *  关于我们
 *
 *  @param success_
 *  @param failure_
 *
 *  @return
 */
+ (NSURLSessionDataTask *)doFetchAboutUs:(void (^)(id responseObject,NSString *message))success_
                                 failure:(void (^)(NSString *message))failure_
{
    return [[ServiceUtils commonHTTPManager] GET:url_net_about parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        
        if (responseObject && [responseObject isKindOfClass:[NSDictionary class]]) {
            
            success_(responseObject,@"获取成功");
        }
        else {
            if (failure_) {
                failure_(@"网络不给力");
            }
        }
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        if (failure_) {
            failure_(@"网络不给力");
        }
    }];
}

/**
 *  免责声明
 *
 *  @param success_
 *  @param failure_
 *
 *  @return
 */
+ (NSURLSessionDataTask *)doFetchCopyright:(void (^)(id responseObject,NSString *message))success_
                                   failure:(void (^)(NSString *message))failure_
{
    return [[ServiceUtils commonHTTPManager] GET:url_net_Copyright parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        
        if (responseObject && [responseObject isKindOfClass:[NSDictionary class]]) {
            
            success_(responseObject,@"获取成功");
        }
        else {
            if (failure_) {
                failure_(@"网络不给力");
            }
        }
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        if (failure_) {
            failure_(@"网络不给力");
        }
    }];
}

/**
 *  发表评论
 *
 *  @param commentid_ 评论id
 *  @param id_        如果是评论回复这个id_就有值
 *  @param content_   评论内容
 *  @param userid_    用户id
 *  @param username_  用户昵称
 *  @param success_
 *  @param failure_
 *
 *  @return
 */
+ (NSURLSessionDataTask *)doNewsSendComments:(NSString *)commentid_
                                          andId:(NSString *)id_
                                     content:(NSString *)content_
                                      userid:(NSString *)userid_
                                    username:(NSString *)username_
                                     success:(void (^)(id responseObject,NSString *message))success_
                                     failure:(void (^)(NSString *message))failure_
{
    NSString *urlString = [URL_BASE stringByAppendingString:URL_SUB_POST_COMMENT];
    if (id_) {
        urlString = [urlString stringByAppendingFormat:@"&id=%@",id_];
    }
    NSDictionary *dic = @{@"commentid": commentid_,
                          @"content": content_,
                          @"uct":[self getAuthCode],
                          @"userid": userid_ == nil ? @"" : userid_,
                          @"username": username_ == nil ? @"" : username_,
                          };
    
    return [[ServiceUtils commonHTTPManager] POST:urlString parameters:dic success:^(NSURLSessionDataTask *task, id responseObject) {
        
        if (responseObject && [responseObject isKindOfClass:[NSDictionary class]]) {
            
            NSInteger code = [[responseObject objectForKey:@"success"] integerValue];
            NSString *message = [responseObject objectForKey:@"msg"];
            
            if (code == 1) {
                success_(message,@"评论成功");
            }
            else {
                failure_(message);
            }
            
        }
        else {
            failure_(@"网络不给力");
        }    } failure:^(NSURLSessionDataTask *task, NSError *error) {
            if (failure_) {
                failure_(@"网络不给力");
            }
        }];
}

/**
 *  获取我的个人评论
 *
 *  @param userid_    我的用户id
 *  @param success_
 *  @param failure_
 *
 *  @return
 */
+ (NSURLSessionDataTask *)doFetchMyComments:(NSString *)userid_
                                    success:(void (^)(id responseObject,NSString *message))success_
                                    failure:(void (^)(NSString *message))failure_
{
    NSString *urlString = [URL_BASE stringByAppendingString:URL_SUB_GET_MY_COMMENT];
    urlString = [urlString stringByAppendingFormat:@"&userid=%@",userid_];
    
    return [[ServiceUtils commonHTTPManager] GET:urlString parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        
        NSInteger code = [[responseObject objectForKey:@"success"] integerValue];
        NSString *message = [responseObject objectForKey:@"msg"];
        NSArray *datas = [responseObject objectForKey:@"data"];
        
        if (code == 1) {
            
            NSArray *reports = [MTLJSONAdapter modelsOfClass:[M_MyComment class] fromJSONArray:datas error:nil];
            if (!reports) {
                reports = @[];
            }
            success_(reports,@"获取成功");
        }
        else {
            if (failure_) {
                failure_(message);
            }
        }
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        if (failure_) {
            failure_(@"网络不给力");
        }
    }];
}

/**
 *  获取广告
 *
 *  @param success_
 *  @param failure_
 *
 *  @return
 */
+ (NSURLSessionDataTask *)doFetchAD:(void (^)(id responseObject,NSString *message))success_
                            failure:(void (^)(NSString *message))failure_
{
    NSString *urlStr = [NSString stringWithFormat:@"%@&uct=%@",URL_SUB_GET_AD,[self getAuthCode]];
    
    return [[ServiceUtils commonHTTPManager] GET:urlStr parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        
        NSInteger code = [[responseObject objectForKey:@"success"] integerValue];
        NSString *message = [responseObject objectForKey:@"msg"];
        NSDictionary *data = [responseObject objectForKey:@"data"];
        
        if (code == 1) {
            NSArray *imgs = [data objectForKey:@"imgs"];
            if (imgs && [imgs isKindOfClass:[NSArray class]] && [imgs count] > 0) {
                [[SDWebImageDownloader sharedDownloader] downloadImageWithURL:[NSURL URLWithString:[[[data objectForKey:@"imgs"] objectAtIndex:0] objectForKey:@"url"]] options:SDWebImageDownloaderUseNSURLCache progress:^(NSInteger receivedSize, NSInteger expectedSize,NSURL * url) {
                    
                } completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {
                    [[SDImageCache sharedImageCache] storeImage:image forKey:@"adImage" toDisk:YES completion:nil];
                }];
            }
            success_(data,@"获取成功");
        }
        else {
            if (failure_) {
                failure_(message);
            }
        }
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        if (failure_) {
            failure_(@"网络不给力");
        }
    }];
}

/**
 *  获取站内私信
 *
 *  @param success_
 *  @param failure_
 *
 *  @return
 */
+ (NSURLSessionDataTask *)doFetchPrivateLetter:(void (^)(id responseObject,NSString *message))success_
                                       failure:(void (^)(NSString *message))failure_
{
    return [[ServiceUtils commonHTTPManager] GET:URL_SUB_GET_PRIVATE_LETTER parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        
        NSInteger code = [[responseObject objectForKey:@"success"] integerValue];
        NSString *message = [responseObject objectForKey:@"msg"];
        NSArray *data = [responseObject objectForKey:@"data"];

        if (code == 1)
        {
            NSArray *letters = [MTLJSONAdapter modelsOfClass:[M_Letter class] fromJSONArray:data error:nil];
            if (!letters) {
                letters = @[];
            }
            success_(letters,@"获取成功");
        }
        else
        {
            if (failure_) {
                failure_(message);
            }
        }
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        if (failure_) {
            failure_(@"网络不给力");
        }
    }];
}


/**
 *  报料点赞
 *
 *  @param baoliaoid_ 报料id
 *  @param success_
 *  @param failure_
 *
 *  @return
 */
+ (NSURLSessionDataTask *)doZanBaoLiao:(NSString *)baoliaoid_
                               success:(void (^)(id responseObject,NSString *message))success_
                               failure:(void (^)(NSString *message))failure_
{
    NSString *urlString = [URL_SUB_ZAN_BAOLIAO stringByAppendingFormat:@"&baoliaoid=%@&uct=%@",baoliaoid_,[self getAuthCode]];
    
    return [[ServiceUtils commonHTTPManager] POST:urlString parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        success_(nil,@"发送成功");
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        if (failure_) {
            failure_(@"网络不给力");//返回的不是json不用管
        }
    }];
}

/**
 *  文章点赞
 *
 *  @param catid_ 频道ID
 *  @param aid_ 文章id
 *  @param success_
 *  @param failure_
 *
 *  @return
 */
+ (NSURLSessionDataTask *)doZanNews:(NSString *)catid_
                                aid:(NSString *)aid_
                            success:(void (^)(id responseObject,NSString *message))success_
                            failure:(void (^)(NSString *message))failure_
{
    NSString *urlString = [URL_SUB_ZAN_NEWS stringByAppendingFormat:@"&catid=%@&aid=%@&uct=%@",catid_,aid_,[self getAuthCode]];
    
    return [[ServiceUtils commonHTTPManager] POST:urlString parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        success_(nil,@"发送成功");
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        if (failure_) {
            failure_(@"网络不给力");//返回的不是json不用管
        }
    }];
}

/**
 *  评论点赞
 *
 *  @param commentid_ 评论文章的ID
 *  @param Id_   ID
 *  @param success_
 *  @param failure_
 *
 *  @return
 */
+ (NSURLSessionDataTask *)doZanComments:(NSString *)commentid_
                                  andId:(NSString *)Id_
                                success:(void (^)(id responseObject,NSString *message))success_
                                failure:(void (^)(NSString *message))failure_
{
    NSString *urlString = [URL_SUB_ZAN_COMMENT stringByAppendingFormat:@"&commentid=%@&id=%@&uct=%@",commentid_,Id_,[self getAuthCode]];
    
    return [[ServiceUtils commonHTTPManager] POST:urlString parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        success_(nil,@"发送成功");
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        if (failure_) {
            failure_(@"网络不给力");//返回的不是json不用管
        }
    }];
}

/**
 *  评论回复
 *
 *  @param commentid_ 评论文章的ID
 *  @param Id_   ID
 *  @param success_
 *  @param failure_
 *
 *  @return
 */
+ (NSURLSessionDataTask *)doReplyComments:(NSString *)commentid_
                                    andId:(NSString *)Id_
                                  content:(NSString *)content_
                                   userid:(NSString *)userid_
                                 username:(NSString *)username_
                                  success:(void (^)(id responseObject,NSString *message))success_
                                  failure:(void (^)(NSString *message))failure_
{
    NSDictionary *dic = @{@"commentid": commentid_,
                          @"Id": Id_,
                          @"content": content_,
                          @"uct":[self getAuthCode],
                          @"userid": userid_ == nil ? @"" : userid_,
                          @"username": username_ == nil ? @"" : username_,
                          };
    
    return [[ServiceUtils commonHTTPManager] POST:URL_SUB_REPLY_COMMENT parameters:dic success:^(NSURLSessionDataTask *task, id responseObject) {
        
        if (responseObject && [responseObject isKindOfClass:[NSDictionary class]]) {
            
            NSInteger code = [[responseObject objectForKey:@"success"] integerValue];
            NSString *message = [responseObject objectForKey:@"msg"];
            
            if (code == 1) {
                success_(message,@"评论成功");
            }
            else {
                failure_(message);
            }
            
        }
        else {
            failure_(@"网络不给力");
        }    } failure:^(NSURLSessionDataTask *task, NSError *error) {
            if (failure_) {
                failure_(@"网络不给力");
            }
        }];
}

/**
 *  获取记者回音
 *
 *  @param success_
 *  @param failure_
 *
 *  @return
 */
+ (NSURLSessionDataTask *)doFetchNewsManReplyList:(NSInteger)pageIndex_
                                         pageSize:(NSInteger)pageSize_
                                          success:(void (^)(id responseObject,NSString *message))success_
                                          failure:(void (^)(NSString *message))failure_
{
    NSString *urlString = [URL_SUB_GET_NEWSMAN_REPLY stringByAppendingFormat:@"&pageindex=%ld&pagesize=%ld",pageIndex_,pageSize_];

    return [[ServiceUtils commonHTTPManager] GET:urlString parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        
        NSInteger code = [[responseObject objectForKey:@"success"] integerValue];
        NSString *message = [responseObject objectForKey:@"msg"];
        NSArray *data = [[responseObject objectForKey:@"data"] objectForKey:@"items"];
        
        if (code == 1)
        {
            NSError *erro;
            NSArray *reports = [MTLJSONAdapter modelsOfClass:[M_Report class] fromJSONArray:data error:&erro];
            if (!reports) {
                reports = @[];
            }
            success_(reports,@"获取成功");
        }
        else
        {
            if (failure_) {
                failure_(message);
            }
        }
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        if (failure_) {
            failure_(@"网络不给力");
        }
    }];
}

/**
 *  获取我的ip
 *
 *  @param success_
 *  @param failure_
 *
 *  @return
 */
+ (NSURLSessionDataTask *)doFetchMyIp:(void (^)(id responseObject,NSString *message))success_
                              failure:(void (^)(NSString *message))failure_
{
    
    NSURL *url = [NSURL URLWithString:URL_SUB_GET_IP];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    request.HTTPMethod = @"GET";
    NSURLSessionConfiguration *config = [NSURLSessionConfiguration defaultSessionConfiguration];
    NSURLSession *session = [NSURLSession sessionWithConfiguration:config];
    NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
        NSString *resString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
        resString = [resString stringByReplacingOccurrencesOfString:@"var returnCitySN =" withString:@""];
        resString = [resString stringByReplacingOccurrencesOfString:@";" withString:@""];
        NSData *jsonData = [resString dataUsingEncoding:NSUTF8StringEncoding];
        NSDictionary *resObject = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingAllowFragments error:nil];
        NSString *code = [resObject objectForKey:@"cip"];
        if (code && [code isKindOfClass:[NSString class]] && [code length] > 0) {
            [AccountManager sharedAccountManager].f_ip = code;
            if (success_) {
                success_(code,@"获取成功");
            }
        } else {
            if (failure_) {
                NSLog(@"%@",error);
                failure_(@"网络不给力");
            }
        }
    }];
    [task resume];
    return task;
}

+ (NSString *)getAuthCode
{
    return [AccountManager sharedAccountManager].f_authCode;
}

/**
 *  发表提问
 *
 *  @param zhuanjia_id 专家id
 *  @param content_   提问内容
 *  @param userid_    用户id
 *  @param success_
 *  @param failure_
 *
 *  @return
 */
+ (NSURLSessionDataTask *)doQuestionSend:(NSString *)zhuanjia_id
                                         content:(NSString *)content_
                                          userid:(NSString *)userid_
                                         success:(void (^)(id responseObject,NSString *message))success_
                                         failure:(void (^)(NSString *message))failure_
{
    NSString *urlString = URL_SUB_POST_QUESTION;
    NSDictionary *dic = @{@"zhuanjia_id": zhuanjia_id,
            @"content": content_,
            @"uct":[self getAuthCode],
            @"userid": userid_ == nil ? @"" : userid_,
            };
    
    return [[ServiceUtils commonHTTPManager] POST:urlString parameters:dic success:^(NSURLSessionDataTask *task, id responseObject) {
        
        if (responseObject && [responseObject isKindOfClass:[NSDictionary class]]) {
            
            NSInteger code = [[responseObject objectForKey:@"success"] integerValue];
            NSString *message = [responseObject objectForKey:@"msg"];
            
            if (code == 200) {
                success_(message,@"问题提交成功");
            }
            else {
                failure_(message);
            }
            
        }
        else {
            failure_(@"网络不给力");
        }    } failure:^(NSURLSessionDataTask *task, NSError *error) {
            if (failure_) {
                failure_(@"网络不给力");
            }
        }];
}

/**
 *  发表问题评论
 *
 *  @param wbreplyid_ 问题id
 *  @param content_   提问内容
 *  @param userid_    用户id
 *  @param success_
 *  @param failure_
 *
 *  @return
 */
+ (NSURLSessionDataTask *)doQuestionCommentSend:(NSString *)wbreplyid_
                                        content:(NSString *)content_
                                         userid:(NSString *)userid_
                                           type:(NSString *)type_
                                      commentid:(NSString *)commentid_
                                        success:(void (^)(id responseObject,NSString *message))success_
                                        failure:(void (^)(NSString *message))failure_
{
    NSString *urlString = URL_SUB_POST_QUESTION_COMMENT;
    NSDictionary *dic = nil;
    if(commentid_){
        dic = @{@"wbreplyid": wbreplyid_,
                @"content": content_,
                @"uct":[self getAuthCode],
                @"userid": userid_ == nil ? @"" : userid_,
                @"type": type_ ,
                @"commentid": commentid_
                };
    }else{
        dic = @{@"wbreplyid": wbreplyid_,
                @"content": content_,
                @"uct":[self getAuthCode],
                @"userid": userid_ == nil ? @"" : userid_,
                @"type": type_
                };
    }
    
    
    return [[ServiceUtils commonHTTPManager] POST:urlString parameters:dic success:^(NSURLSessionDataTask *task, id responseObject) {
        
        if (responseObject && [responseObject isKindOfClass:[NSDictionary class]]) {
            
            NSInteger code = [[responseObject objectForKey:@"success"] integerValue];
            NSString *message = [responseObject objectForKey:@"msg"];
            
            if (code == 200) {
                success_(message,@"评论提交成功");
            }
            else {
                failure_(message);
            }
            
        }
        else {
            failure_(@"网络不给力");
        }    } failure:^(NSURLSessionDataTask *task, NSError *error) {
            if (failure_) {
                failure_(@"网络不给力");
            }
        }];
}


/**
 *  获取问题评论
 *
 *  @param urlString_ 请求链接
 *  @param success_
 *  @param failure_
 *
 *  @return
 */
+ (NSURLSessionDataTask *)doFetchQuestionComments:(NSString *)urlString_
                                     success:(void (^)(id responseObject,NSString *message))success_
                                     failure:(void (^)(NSString *message))failure_
{
    return [[ServiceUtils commonHTTPManager] GET:urlString_ parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        
        NSInteger code = [[responseObject objectForKey:@"success"] integerValue];
        NSString *message = [responseObject objectForKey:@"msg"];
        NSArray *datas = [responseObject objectForKey:@"data"];
        
        if (code == 200) {
            
            NSArray *comments = [MTLJSONAdapter modelsOfClass:[M_QuestionComment class] fromJSONArray:datas error:nil];
            if (!comments) {
                comments = @[];
            }
            success_(comments,@"获取成功");
        }
        else {
            if (failure_) {
                failure_(message);
            }
        }
    }
                                         failure:^(NSURLSessionDataTask *task, NSError *error) {
                                             if (failure_) {
                                                 failure_(@"网络不给力");
                                             }
                                         }];
}

/**
 *  问吧点赞
 *
 *  @param id_ ID
 *  @param type_ 专家/评论
 *  @param success_
 *  @param failure_
 *
 *  @return
 */
+ (NSURLSessionDataTask *)doZanQuestion:(NSString *)id_
                                   type:(NSString *)type_
                            success:(void (^)(id responseObject,NSString *message))success_
                            failure:(void (^)(NSString *message))failure_
{
    NSString *urlString = [URL_SUB_POST_QUESTION_ZAN stringByAppendingFormat:@"&id=%@&type=%@&uct=%@",id_,type_,[self getAuthCode]];
    
    return [[ServiceUtils commonHTTPManager] POST:urlString parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        success_(nil,@"发送成功");
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        if (failure_) {
            failure_(@"网络不给力");//返回的不是json不用管
        }
    }];
}




/**
 *  获取新闻列表
 *
 *  @param type_    1 刷新  2 加载更多
 *  @param subURL_  子链接
 *  @param success_
 *  @param failure_
 *
 *  @return
 */
+ (NSURLSessionDataTask *)doHotNewsList:(NSString *)suburl_
                              pageindex:(NSInteger)pageindex_
                               pagesize:(NSInteger)pagesize_
                                success:(void (^)(id responseObject,NSString *message))success_
                                failure:(void (^)(NSString *message))failure_
{
    NSString *urlString = [NSString stringWithFormat:@"%@&pageindex=%ld&pagesize=%ld",suburl_,pageindex_,pagesize_];
    
    return [[ServiceUtils commonHTTPManager] GET:urlString parameters:nil progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask *task, id responseObject) {
        
        NSMutableDictionary *resDic = [NSMutableDictionary dictionary];
        
        if (responseObject && [responseObject isKindOfClass:[NSArray class]]) {
            for (NSDictionary *itemDic in responseObject) {
                
                NSString *type = [itemDic objectForKey:@"type"];
                if ([type isEqualToString:@"focus"]) {
                    //焦点图
                    NSArray *dataArray = [itemDic objectForKey:@"item"];
                    NSArray *focus = [MTLJSONAdapter modelsOfClass:[M_News class] fromJSONArray:dataArray error:nil];
                    if (!focus) {
                        focus = @[];
                    }
                    
                    [resDic setObject:focus forKey:@"focus"];
                }
                
                if ([type isEqualToString:@"data"]) {
                    NSError *error;
                    NSArray *dataArray = [itemDic objectForKey:@"data"];
                    NSArray *list = [MTLJSONAdapter modelsOfClass:[M_News class] fromJSONArray:dataArray error:&error];
                    if (!list) {
                        list = @[];
                    }
                    [resDic setObject:list forKey:@"list"];
                    
                }
            }
        }else if (responseObject && [responseObject isKindOfClass:[NSDictionary class]]){
            NSError *error;
            NSArray *dataArray = [responseObject objectForKey:@"data"];
            NSArray *list = [MTLJSONAdapter modelsOfClass:[M_News class] fromJSONArray:dataArray error:&error];
            if (!list) {
                list = @[];
            }
            [resDic setObject:list forKey:@"list"];
        }
        success_(resDic,@"获取成功");
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        if (failure_) {
            failure_(@"网络不给力");
        }
    }];
}

/**
 *  直播新闻详情
 *
 *  @param suburl_ 请求url
 *  @param success_
 *  @param failure_
 *
 *  @return
 */
+ (NSURLSessionDataTask *)doPlayNewsDetail:(NSString *)suburl_
                                    lid:(NSString *)lid_
                                   type:(NSString *)type_
                                success:(void (^)(id responseObject,NSString *message))success_
                                failure:(void (^)(NSString *message))failure_
{
    NSString *urlString = [NSString stringWithFormat:@"%@&lid=%@&type=%@",suburl_,lid_,type_];
    
    return [[ServiceUtils commonHTTPManager] GET:urlString parameters:nil progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask *task, id responseObject) {
        NSNumber *code = responseObject[@"code"];
        if(code.intValue==200) {
            NSDictionary *dataDict = [responseObject objectForKey:@"data"];
            M_PlayNewsDetail *detail = [MTLJSONAdapter modelOfClass:[M_PlayNewsDetail class] fromJSONDictionary:dataDict error:nil];
            success_(detail,@"获取成功");
        }else {
            failure_(@"不是视频或直播新闻");
        }
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        if (failure_) {
            failure_(@"网络不给力");
        }
    }];
    
}



/**
 *  直播新闻详情
 *
 *  @param suburl_ 请求url
 *  @param success_
 *  @param failure_
 *
 *  @return
 */
+ (NSURLSessionDataTask *)doPlayHotWords:(NSString *)suburl_
                                   success:(void (^)(id responseObject,NSString *message))success_
                                   failure:(void (^)(NSString *message))failure_
{
    return [[ServiceUtils commonHTTPManager] GET:suburl_ parameters:nil progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask *task, id responseObject) {
        NSArray *words = (NSArray *)responseObject;
        success_(words,@"获取成功");
//        NSNumber *code = responseObject[@"code"];
//        if(code.intValue==200) {
//            NSDictionary *dataDict = [responseObject objectForKey:@"data"];
//            M_PlayNewsDetail *detail = [MTLJSONAdapter modelOfClass:[M_PlayNewsDetail class] fromJSONDictionary:dataDict error:nil];
//            success_(detail,@"获取成功");
//        }else {
//            failure_(@"不是视频或直播新闻");
//        }
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        if (failure_) {
            failure_(@"网络不给力");
        }
    }];
    
}

/**
 *  APP打开宣传图片接口
 *
 *  @param suburl_ 请求url
 *  @param success_
 *  @param failure_
 *
 *  @return
 */
+ (NSURLSessionDataTask *)doFetchAppOpenImage:(NSString *)suburl_
                                      success:(void (^)(id responseObject,NSString *message))success_
                                      failure:(void (^)(NSString *message))failure_
{
    return [[ServiceUtils commonHTTPManager] GET:suburl_ parameters:nil progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask *task, id responseObject) {
        NSNumber *code = responseObject[@"success"];
        if(code.intValue==1) {
            NSDictionary *dataDict = [responseObject objectForKey:@"data"];
            M_AppOpenImage *detail = [[M_AppOpenImage alloc] init];
            detail.f_id = [dataDict valueForKey:@"id"];
            detail.f_wakeupThumb =[dataDict valueForKey:@"wakeupThumb"];
            detail.f_wakeUpPic =[dataDict valueForKey:@"wakeUpPic"];
            NSString *secstr = [dataDict valueForKey:@"seconds"];
            if(secstr) {
                detail.f_seconds = [secstr integerValue];
            }
            detail.f_wakeupUrl = [dataDict valueForKey:@"wakeupUrl"];
            detail.f_refreshTags = [dataDict valueForKey:@"refreshTags"];
            
            //M_AppOpenImage *detail = [MTLJSONAdapter modelOfClass:[M_AppOpenImage class] fromJSONDictionary:dataDict error:nil];
            success_(detail,@"获取成功");
        }else {
            failure_(@"无法获取信息");
        }

    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        if (failure_) {
            failure_(@"网络不给力");
        }
    }];
    
}

+ (NSURLSessionDataTask *)doFetchLocationNews:(NSString *)posid
                                      pageindex:(NSInteger)pageindex_
                                       pagesize:(NSInteger)pagesize_
                                      success:(void (^)(id, NSString *))success_ failure:(void (^)(NSString *))failure_ {
    NSString *urlString = [NSString stringWithFormat:url_fetch_location_news, posid];
    urlString = [urlString stringByAppendingFormat:@"&pageindex=%ld&pagesize=%ld",pageindex_,pagesize_];

    return [[ServiceUtils commonHTTPManager] GET:urlString parameters:nil progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask *task, id responseObject) {
        if (responseObject && [responseObject isKindOfClass:[NSDictionary class]]) {
            NSInteger code = [[responseObject objectForKey:@"success"] integerValue];
            NSString *message = [responseObject objectForKey:@"msg"];
            NSArray *data = [[responseObject objectForKey:@"data"] objectForKey:@"rows"];
            
            if (code == 0) {
                
                NSError *error;
                NSArray *list = [MTLJSONAdapter modelsOfClass:[M_News class] fromJSONArray:data error:&error];
                if (!list) {
                    list = @[];
                }

                
                success_(list,message);
            } else {
                failure_(message);
            }
        }
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        if (failure_) {
            failure_(@"网络不给力");
        }
    }];
}

+ (NSURLSessionDataTask *)doFetchMoreNews:(NSInteger)pageindex_ pagesize:(NSInteger)pagesize_ success:(void (^)(id, NSString *))success_ failure:(void (^)(NSString *))failure_ {
    NSString *urlString = [NSString stringWithFormat:url_fetch_location_news, @"47"];
    urlString = [urlString stringByAppendingFormat:@"&pageindex=%ld&pagesize=%ld",pageindex_,pagesize_];

    return [[ServiceUtils commonHTTPManager] GET:urlString parameters:nil progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask *task, id responseObject) {
        if (responseObject && [responseObject isKindOfClass:[NSDictionary class]]) {
            NSInteger code = [[responseObject objectForKey:@"success"] integerValue];
            NSString *message = [responseObject objectForKey:@"msg"];
            NSArray *data = [[responseObject objectForKey:@"data"] objectForKey:@"rows"];
            
            if (code == 0) {
                
                NSError *error;
                NSArray *list = [MTLJSONAdapter modelsOfClass:[M_News class] fromJSONArray:data error:&error];
                if (!list) {
                    list = @[];
                }

                
                success_(list,message);
            } else {
                failure_(message);
            }
        }
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        if (failure_) {
            failure_(@"网络不给力");
        }
    }];
}

@end
